//
//  EntertainmentViewController.m
//  ZAKER
//
//  Created by dllo on 15/8/21.
//  Copyright (c) 2015年 蓝鸥科技. All rights reserved.
//

#import "EntertainmentViewController.h"


@interface EntertainmentViewController ()<CitySearchViewControllerDelegate>


@property (nonatomic, retain) UIButton *direcButton; // 定位按钮
@property (nonatomic, retain) EFAnimationViewController *efaViewController; // 定义旋转抽屉效果的实行vc
@property (nonatomic, retain) UILabel *cityLabel; // 第二页点击返回城市名
@property (nonatomic, retain) NSString *cityCode; // 第二页点击返回城市编码


@end

@implementation EntertainmentViewController

-(void)dealloc
{
    
    [_direcButton release];
    [_efaViewController release];
    [_cityCode release];
    [_cityLabel release];
    
    [_efaViewController.view removeFromSuperview];
    [_efaViewController removeFromParentViewController];
    
    [super dealloc];
    
}


-(instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    
    if (self) {
    }
    return self;
}


- (void)viewDidLoad
{
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor clearColor];
    self.navigationController.navigationBar.translucent = NO;
    self.automaticallyAdjustsScrollViewInsets = NO;

    
    self.navigationController.navigationBar.barTintColor  = RGBACOLOR(135, 206, 255, 1);
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(self.view.frame.size.width / 2 + 37.5 * myWidth, 12 , 75 * myWidth, 40 * myHeight)];
    label.text = @"玩乐";
    label.textAlignment = 1;
    self.navigationItem.titleView = label;
    [label release];
    
    [self createDirecButton];
    [self createEFA];
    
    
    self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc]initWithCustomView:_direcButton] autorelease];
}



#pragma mark - 选择城市按钮
-(void)createDirecButton
{
    
    self.direcButton = [[[UIButton alloc]initWithFrame:CGRectMake(0, 0, 25 * myWidth, 25 * myHeight)] autorelease];
    [_direcButton setImage:[UIImage imageNamed:@"dingwei.png"] forState:UIControlStateNormal];
    [_direcButton addTarget:self action:@selector(direcButtonAction) forControlEvents:UIControlEventTouchUpInside];    
    
    self.cityLabel = [[[UILabel alloc]initWithFrame:CGRectMake(270 *  myWidth, 12 , 88 * myWidth, 20 * myHeight)] autorelease];
    [self.navigationController.navigationBar addSubview:_cityLabel];
    _cityLabel.font = [UIFont systemFontOfSize:15];
    _cityLabel.textAlignment = 1;
    _cityLabel.text = @"北京";
    _cityLabel.textColor = [UIColor whiteColor];
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    [user setObject:@"beijing" forKey:@"cityCode"];
    
}


#pragma mark - 定位城市按钮, 点击事件
-(void)direcButtonAction
{
    CitySearchViewController *city = [[CitySearchViewController alloc]init];
    city.delegate = self;
    [self.navigationController pushViewController:city animated:YES];
    [city release];
}



#pragma mark -  协议传值, cityCode用于数据解析
-(void)sendCityName:(NSString *)cityName cityCode:(NSString *)cityCode
{
    self.cityLabel.text = cityName;
    self.cityCode = cityCode;
}



#pragma mark -  旋转抽屉
-(void)createEFA
{
    self.efaViewController = ({EFAnimationViewController *vc = [[EFAnimationViewController alloc] init];

        [self.view addSubview:vc.view];
        [self addChildViewController:vc];
        [vc didMoveToParentViewController:self];
        vc;
        
    });
}



- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}


@end
